TK!2
=v
#1
:n

:s
b
:c
 DEFINITE INTEGRALS -- SIMPSON'S RULE
#3
:n

:s
b
:c
First Example: built-in sin function
#4
:n
fun
:v
'sin
:s
i
:c
name of function to be integrated
#5
:n
a
:v
0
:s
i
:c
lower integration limit
#6
:n
b
:v
1.570796326794897
:s
i
:c
upper integration limit
#7
:n
n
:v
10
:s
i
:c
# of integration steps (must be even)
#8
:n
res1
:v
1.0000033922209
:s
o
:c
integral of sin(x) from 0 to pi()/2
#9
:n

:s
b
:c
(exact value is 1)
#11
:n

:s
b
:c
Second Example: elliptical integral of
#12
:n

:s
b
:c
1st kind (unobtainable in closed form)
#13
:n
fun2
:v
'elinfk
:s
i
:c
function name
#14
:n
ą
:v
0
:s
i
:u
rad
:d
deg
:c
lower limit
#15
:n
į
:v
.7853981634
:s
i
:u
rad
:d
deg
:c
upper limit
#16
:n
k
:v
.5
:s
i
:c
parameter
#17
:n
res2
:v
.804365981889081
:s
o
:c
elliptical integral of the 1st kind
#19
:n

:s
b
:c
[See the Rule Sheet (=R) for notes]
=u
#1
:f
rad
:m
57.2957795129
:t
deg
=l
=f
#1
:n
Simpson
:c
Definite integral, Simpson rule
:t
Procedure
:i
fun,a,b,n
:o
value
#2
:n
elinfk
:c
Integrand for elliptical int. of 1st kind
:t
Rule
:p
k
:a
phi
:v
z
#1
:n
Simpson
:z
" Notation:  fun    name of rule, procedure or built-in function 
"                   defining the integrand
"            a,b    lower and upper limits
"            n      number of integration steps (must be even number)
"            value  value of definite integral

" Description: Standard method of numerical integration using second-degree
"              polynomial approximation of integrand.

if mod(n,2)<>0 then error:= odd_number_of_intervals
h:= (b-a)/n
x:= a
k:= 1
value:= 0
for i=2 to n
    x:= x + h
    k:= 3 - k
    value:= value + k*apply(fun,x)
next i
value:= (2*value+apply(fun,a)+apply(fun,b))*h/3
/E
E
#2
:n
elinfk
:z
z = 1/sqrt(1-(k*sin(phi))^2)
/E
E
=r
#1
:r
res1 = Simpson(fun,a,b,n)                 " See Function Sheet for details.
#2
:r
res2 = Simpson(fun2,ą,į,n) 
#4
:r
" The variable "fun" is assigned the value  'sin  and "fun2" is assigned the
:s
C
#5
:r
" value  'elifnk  (where "elifnk" is a user-defined rule function), hence
:s
C
#7
:r
"                                         ō į
:s
C
#8
:r
"           ō b                           ³     
:s
C
#9
:r
"           ³                             ³          d phi
:s
C
#10
:r
"   res1 =  ³  sin x dx           res2 =  ³ ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
:s
C
#11
:r
"           ³                             ³    ___________________
:s
C
#12
:r
"           õ a                           ³   ū  1  -  kż sinżphi
:s
C
#13
:r
"                                         õ ą
:s
C
=p
=t
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
No
:a
Yes
:r
Yes
:h
No
:t
1
:n
No
:d
LPT1
%Tv,f,0,5,0,1,0
